package com.zxjbyte.yiyi.module.system.service.oss.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zxjbyte.yiyi.framework.mybatis.service.impl.BaseServiceXImpl;
import com.zxjbyte.yiyi.module.system.convert.oss.OssRecordConvert;
import com.zxjbyte.yiyi.module.system.domain.dto.oss.OssRecordAddDTO;
import com.zxjbyte.yiyi.module.system.domain.dto.oss.OssRecordDelDTO;
import com.zxjbyte.yiyi.module.system.domain.entity.OssRecordPO;
import com.zxjbyte.yiyi.module.system.mapper.oss.OssRecordMapper;
import com.zxjbyte.yiyi.module.system.service.oss.IOssRecordService;
import org.springframework.stereotype.Service;

/**
 * Oss上传日志业务处理类
 *
 * @Author zhangxingjia
 * @Date 2023/5/9 16:07
 * @Version: 1.0
 */
@Service
public class OssRecordServiceImpl extends BaseServiceXImpl<OssRecordMapper, OssRecordPO> implements IOssRecordService {

    @Override
    public void addRecord(OssRecordAddDTO addDto) {
        save(OssRecordConvert.INSTANCE.addConvert(addDto));
    }

    @Override
    public boolean deleteByPath(OssRecordDelDTO delDto) {
        return update(Wrappers.<OssRecordPO>lambdaUpdate().set(OssRecordPO::getDeleted, true)
                .set(OssRecordPO::getUpdateUser, delDto.getUpdateUser())
                .set(OssRecordPO::getUpdateTime, delDto.getUpdateTime())
                .eq(OssRecordPO::getPath, delDto.getPath()));
    }
}
